﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.IO;
using ScarfMaker.Properties;

namespace ScarfMaker.Dal
{
    public static class DataBase
    {
        public static bool ValidateUser(string username,string password)
        {
            if(File.Exists("Database.xml"))
            {
                XElement root = XElement.Load("Database.xml");
                return root.Elements("user").Count(m => m.Attribute("name").Value == username && m.Attribute("password").Value == password) > 0;
            }
            else
            {
                using(FileStream fs=File.Create("Database.xml"))
                {

                    using(StreamWriter sw=new StreamWriter(fs))
                    {

                        sw.Write(Resources.DatabaseXML);
                        return true;
                    }
                }
            }
        }
    }
}
